using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;

namespace DungeonOfDespair
{
    public partial class MainForm : Form
    {
        private GameState m_gameState;

        private void m_tmrGame_Tick(object sender, EventArgs e)
        {
            switch (m_gameState.NextState)
            {
                case GameStateType.Title: m_gameState = new GameStateTitle(); break;
                case GameStateType.Play: m_gameState = new GameStatePlay(); break;
                case GameStateType.Loading: m_gameState = new GameStateLoading(); break;
                case GameStateType.GameOver: m_gameState = new GameStateOver(); break;
                case GameStateType.GameWon: m_gameState = new GameStateWon(); break;
            }

            m_gameState.Update();

            Invalidate();
        }

        private void MainForm_KeyDown(object objectSender, KeyEventArgs keyEventArgs)
        {
            m_gameState.OnKeyDown(objectSender, keyEventArgs);
        }

        private void MainForm_KeyUp(object objectSender, KeyEventArgs keyEventArgs)
        {
            m_gameState.OnKeyUp(objectSender, keyEventArgs);
        }

        protected override void OnPaint(PaintEventArgs paintEventArgs)
        {
            if (m_gameState == null) return;

            Graphics graphics = paintEventArgs.Graphics;
            m_gameState.Draw(graphics);
        }

        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            m_gameState = new GameStateTitle();
            m_tmrGame.Enabled = true;
        }

    }
}